# coding:utf-8
"""
description:登录页
"""
from appium.webdriver.common import mobileby

from common import Base_Page, Log
from config.GlobalParameter import TEST_Element_YAML
from common.Get_Yaml import get_yaml
import os

testData = get_yaml(os.path.join(TEST_Element_YAML, 'Login.yaml'))


class login_page(Base_Page.Base_page):
    by = mobileby.MobileBy()
    """login"""
    etUser_loc = (by.ID, testData.get_elementInfo(1))
    etPws_loc = (by.ID, testData.get_elementInfo(2))
    btnLogin_loc = (by.ID, testData.get_elementInfo(0))

    def func_user_login(self, user, pwd):
        """
        登录测试
        :param user:
        :param pwd:
        :param message: 断言内容
        :return:
        """
        self.input_User(user)
        self.input_Pws(pwd)
        self.click_btnLogin()

    def input_User(self, username):
        """输入email"""
        self.send_keys(username, self.find_element(*self.etUser_loc))

    def input_Pws(self, password):
        """输入password"""
        self.send_keys(password, self.find_element(*self.etPws_loc))

    def get_Pws(self):
        """得到password状态"""
        return self.find_element(*self.etPws_loc)

    def click_btnLogin(self):
        """点击登录按钮"""
        self.find_element(*self.btnLogin_loc).click()

    def assertVisible_btnlogin(self):
        """判断btnlogin按钮是否存在"""
        return self.assertVisible(*self.btnLogin_loc)
